home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DMAKE38B.ARJ / RUNARGV.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  3KB  |  120 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/msdos/runargv.c,v 1.1 1992/01/24 03:27:35 dvadura Exp $
  2. -- SYNOPSIS -- run a sub process.
  3. -- 
  4. -- DESCRIPTION
  5. --    Use spawn to run a subprocess.
  6. --
  7. -- AUTHOR
  8. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  9. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  10. --
  11. -- COPYRIGHT
  12. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  13. -- 
  14. --      This program is free software; you can redistribute it and/or
  15. --      modify it under the terms of the GNU General Public License
  16. --      (version 1), as published by the Free Software Foundation, and
  17. --      found in the file 'LICENSE' included with this distribution.
  18. -- 
  19. --      This program is distributed in the hope that it will be useful,
  20. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  21. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. --      GNU General Public License for more details.
  23. -- 
  24. --      You should have received a copy of the GNU General Public License
  25. --      along with this program;  if not, write to the Free Software
  26. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. --
  28. -- LOG
  29. --     $Log: runargv.c,v $
  30.  * Revision 1.1  1992/01/24  03:27:35  dvadura
  31.  * dmake Version 3.8, Initial revision
  32.  *
  33. */
  34.  
  35. #include <process.h>
  36. #include <errno.h>
  37. #include "extern.h"
  38. #include "sysintf.h"
  39.  
  40. static int  _abort_flg = FALSE;
  41. static void _add_child ANSI((CELLPTR, int));
  42. static void _finished_child ANSI((int));
  43.  
  44. PUBLIC int
  45. runargv(target, ignore, group, last, shell, cmd)
  46. CELLPTR target;
  47. int     ignore;
  48. int    group;
  49. int    last;
  50. int    shell;
  51. char    *cmd;
  52. {
  53. #if ! defined(_MSC_VER)
  54.    extern char **environ;
  55. #endif
  56.    int status;
  57.    char **argv;
  58.    char path[MAX_PATH_LEN+1];
  59.  
  60.    argv = Pack_argv( group, shell, cmd );
  61.    _add_child(target, ignore);
  62.  
  63.    /* Preserve the current working directory accross a spawn call 
  64.     * DOS is brain dead about this. */
  65.    strcpy(path,Get_current_dir());
  66.    status = spawnvpe(P_WAIT, *argv, argv, environ);
  67.    Set_dir(path);
  68.  
  69.    if( status == -1 ) Error("%s: %s", argv[0], strerror(errno));
  70.    _finished_child(status);
  71.    if( last && !Doing_bang ) Update_time_stamp( target );
  72.  
  73.    return( 0 );
  74. }
  75.  
  76.  
  77. PUBLIC void
  78. Clean_up_processes()
  79. {
  80.    _abort_flg = TRUE;
  81.    _finished_child(-1);
  82. }
  83.  
  84.  
  85. PUBLIC int
  86. Wait_for_child( abort_flg, pid )
  87. int abort_flg;
  88. int pid;
  89. {
  90.    return(1);
  91. }
  92.  
  93.  
  94. static int     _valid = -1;
  95. static CELLPTR _tg;
  96. static int     _ignore;
  97.  
  98. static void
  99. _add_child( target, ignore )
  100. CELLPTR target;
  101. int    ignore;
  102. {
  103.    _tg = target;
  104.    _ignore = ignore;
  105.    _valid = 0;
  106.  
  107.    Current_target = NIL(CELL);
  108. }
  109.  
  110.  
  111. static void
  112. _finished_child(status)
  113. int    status;
  114. {
  115.    if( _valid == -1 ) return;
  116.    Unlink_temp_files( _tg );
  117.    _valid = -1;
  118.    Handle_result( status, _ignore, _abort_flg, _tg );
  119. }
  120.